// ==UserScript==
// @name chatGPT tools Plus ++(免费版)
// @namespace http://tampermonkey.net/
// @version 0.1.2
// @description chatGPT 免费版,即刻在必应谷歌体验AI,无需注册等待!
// @author Onion
// @match https://cn.bing.com/*
// @match https://www.bing.com/*
// @match https://chat.openai.com/chat
// @match https://www.google.com/*
// @match https://www.google.com.hk/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=openai.com
// @grant GM_xmlhttpRequest
// @grant GM_addStyle
// @require https://cdn.staticfile.org/jquery/3.4.0/jquery.min.js
// @require https://cdn.staticfile.org/jquery-cookie/1.4.1/jquery.cookie.min.js
// @require https://cdn.jsdelivr.net/npm/marked@4.2.3/marked.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/markdown-it/13.0.1/markdown-it.min.js
// @require https://unpkg.com/axios/dist/axios.min.js
// @connect ip-api.com
// @connect chat.openai.com
// @connect gpt.chatapi.art
// @license MIT
// ==/UserScript==
(function() {
'use strict';
var your_qus
if (window.location.href.indexOf("bing.com") > -1) {
creatBox_and_addEventlis(0)
GM_add_box_style(0)
keyEvent()
checkIp()
autoClick()
}
if (window.location.href.indexOf("chat.openai.com") > -1) {
//$.cookie('yourCookie','dumplings', {domain:'qq.com',path:'/'});
console.log("httpOnly保护,没法拿到cookie,自己复制粘贴")
}
if (window.location.href.indexOf("www.google.com") > -1) {
creatBox_and_addEventlis(1)
GM_add_box_style(1)
keyEvent()
checkIp()
autoClick()
}
//顶级函数
function uuid() { //uuid 产生
var s = [];
var hexDigits = "0123456789abcdef";
for (var i = 0; i < 36; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}
s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
s[8] = s[13] = s[18] = s[23] = "-";
var uuid = s.join("");
return uuid;
}
function GM_add_box_style(case_web){
switch (case_web){
case 0://bing
GM_addStyle(`
#gptAnswer{
margin: 15px;
border-top: solid;
border-bottom: solid;
}
#gptInput{
width:74%;
border-radius: 4px;
}
#gptInputBox{
display: flex;
justify-content: space-around;
}
#button_GPT:hover{
background:#ffffffcc;
}
#gptDiv{
border-radius: 8px;
padding: 10px;
margin-bottom: 9px;
width:452px;
translate:-20px;
background:#ffffffcc;
backdrop-filter: blur(5px);
display: flex;
flex-direction: column;
}
#button_GPT{
}
#button_GPT{
background: transparent;
border-radius: 4px;
}
#gptCueBox{
translate: 3px;
}
#dot{
height: 4px;
width: 4px;
display: inline-block;
border-radius: 2px;
animation: dotting 2.4s infinite step-start;
}
@keyframes dotting {
25%{
box-shadow: 4px 0 0 #71777D;
}
50%{
box-shadow: 4px 0 0 #71777D ,14px 0 0 #71777D;
}
75%{
box-shadow: 4px 0 0 #71777D ,14px 0 0 #71777D, 24px 0 0 #71777D;
}
}
`)
break;
case 1: //google
GM_addStyle(`
#gptAnswer{
margin: 15px;
border-top: solid;
border-bottom: solid;
}
#gptInput{
border-radius: 4px;
width: 68%;
}
#button_GPT:hover{
background:#dcdcdccc;
}
#gptDiv{
flex: 1;
display: flex;
flex-direction: column;
height: fit-content;
}
#gptInputBox{
display:flex;
justify-content: space-around;
}
#button_GPT{
background: transparent;
border-radius: 3px;
font-size: 14px;
}
#gptStatus{
margin-left: 7px;
}
#dot{
height: 4px;
width: 4px;
display: inline-block;
border-radius: 2px;
animation: dotting 2.4s infinite step-start;
}
@keyframes dotting {
25%{
box-shadow: 4px 0 0 #71777D;
}
50%{
box-shadow: 4px 0 0 #71777D ,14px 0 0 #71777D;
}
75%{
box-shadow: 4px 0 0 #71777D ,14px 0 0 #71777D, 24px 0 0 #71777D;
}
}
`)
break;
default :
alert("参数没设定")
}
}
function do_it(){
document.getElementById('gptAnswer').innerHTML=`
加载中
`
GM_xmlhttpRequest({
method: "POST",
url: "https://gpt.chatapi.art/backend-api/conversation",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer`,
},
data: JSON.stringify({//抓包conversation就可以看到这个结构
action: "next",
messages: [
{
id: uuid(),
role: "user",
content: {
content_type: "text",
parts: [your_qus],
},
},
],
model: "text-davinci-002-render",
parent_message_id: uuid(),
}),
onloadend: function (data) {
var answer
if (data.response) {
var data_transform=data.response.split("\n\n")
if(data_transform){
try{
data_transform=JSON.parse(data_transform.slice(-3,-2)[0].slice(6))
answer=data_transform.message.content.parts[0]
document.getElementById('gptAnswer').innerHTML=answer
}catch(err){
console.log(`err:${err}`)
}
}
// const answer = JSON.parse(data.response.split("\n\n").slice(-3, -2)[0].slice(6)).message.content.parts[0]
}
},
onerror: function (err) {
console.log(err)
},
ontimeout: function (err) {
throw new Error('timeout!');
}
})
}
function creatBox_and_addEventlis(append_case){
var divE = document.createElement('div');
var divId = document.createAttribute("id"); //创建属性
divId.value = 'gptDiv'; //设置属性值
divE.setAttributeNode(divId); //给div添加属性
var pE = document.createElement('p');
var pClass= document.createAttribute('class');
pClass.value = 'textClass';
pE.setAttributeNode(pClass)
var pText = document.createTextNode("chatGPT tools Plus ++ v0.0.1已启动");
pE.appendChild(pText);
divE.appendChild(pE);
switch (append_case){
case 0:
if(divE){
document.getElementById('b_context').prepend(divE)
}
break;
case 1:
if(document.getElementsByClassName('TQc1id ')[0]){
document.getElementsByClassName('TQc1id ')[0].prepend(divE);
}
else{
document.getElementById("rcnt").appendChild(divE);
}
break;
default :
if(divE){
document.getElementById('b_context').prepend(divE)
}
}
document.getElementById('gptDiv').innerHTML=`
  openAI 已就绪,请输入你的问题
chatGPT tools Plus ++免费版 v0.0.1已启动
`
var search_content
if(append_case===1){
search_content=document.querySelector("#tsf > div:nth-child(1) > div.A8SBwf > div.RNNXgb > div > div.a4bIc > input:nth-child(3)").value
}
if(append_case===0){
search_content=document.getElementsByClassName('b_searchbox')[0].value
}
document.getElementById("gptInput").value=search_content
document.getElementById('button_GPT').addEventListener('click',()=>{
your_qus=document.getElementById("gptInput").value
do_it()
})
}
//焦点函数
function isBlur(){
var myInput = document.getElementById('gptInput');
if (myInput == document.activeElement) {
return 1
} else {
return 0
}
}
function keyEvent(){
document.onkeydown = function (e) {
var keyNum = window.event ? e.keyCode : e.which;
if (13 == keyNum) {
if (isBlur()) {
document.getElementById('button_GPT').click()
}
else{
console.log("失焦不执行")
}
}}
}
function checkIp(){
GM_xmlhttpRequest({
method: "GET",
url: "http://ip-api.com/json/",
onloadend: function (data) {
if(data){
try{
data=JSON.parse(data.response)
}catch(err){
console.log(err)
}
console.log(data.country)
if(data.country=="Hong Kong"){
document.getElementById('gptStatus').innerHTML=`  openAI 已就绪,请输入你的问题`
}
}
else{
document.getElementById('gptStatus').innerHTML=`  openAI 没有就绪,请更换你的IP为非大陆节点`
throw new Error('Error while executing the code');
}
},
onerror: function (err) {
document.getElementById('gptStatus').innerHTML=`  openAI 没有就绪,请更换你的IP为非大陆节点`
throw new Error('Error while executing the code');
},
ontimeout: function (err) {
document.getElementById('gptStatus').innerHTML=`  openAI 没有就绪,请更换你的IP为非大陆节点`
throw new Error('Error while executing the code');
}
})
}
function addBothStyle(){
GM_addStyle(`
@keyframes pulse {
100% {
opacity: 1;
}
50% {
opacity: 0.5;
}
}
`)
}
function setCookie(cname,cvalue,exdays)
{
var d = new Date();
d.setTime(d.getTime()+(exdays*24*60*60*1000));
var expires = "expires="+d.toGMTString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}
//原生cookie函数
function getCookieObject() {
let cookieString = document.cookie;
cookieString = cookieString.substring(0, cookieString.length - 1);
let tempCookieArray = cookieString.split('; ');
let cookieObject = {}; // 存放 cookie 键值对
tempCookieArray.forEach(item => {
let name = item.substring(0, item.indexOf('='));
let value = item.substring(item.indexOf('=') + 1);
value = decodeURIComponent(value); // 还原字符串
cookieObject[name] = value; // 将键值插入中这个对象中
});
return cookieObject // 返回包含 cookie 键值对的对象
}
function autoClick(){
document.getElementById('button_GPT').click()
}
})();